package com.shoppingmall.activity.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.allen.library.SuperTextView;
import com.bumptech.glide.Glide;
import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.widget.TitleBar;
import com.shoppingmall.R;
import com.shoppingmall.widget.BottomSelectPhotosPopwin;
import com.shoppingmall.widget.TipDialog;
import com.yanzhenjie.album.Action;
import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.AlbumFile;
import com.yanzhenjie.album.api.widget.Widget;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 2020/3/14
 * 描述：个人资料
 */
public class PersonalInformActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.stv_avatar)
    SuperTextView stvAvatar;
    @BindView(R.id.stv_account_number)
    SuperTextView stvAccountNumber;
    @BindView(R.id.et_nickname)
    EditText etNickname;

    private String headImgPath;

    @Override
    protected int initLayout() {
        return R.layout.activity_mine_personal_inforamtion;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        TipDialog tipDialog = new TipDialog(mContext);
    }

    @Override
    protected void initEvent() {
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        titleBar.setRightLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        stvAvatar.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() {
            @Override
            public void onClickListener(SuperTextView superTextView) {
                showBottomPopwin();
            }
        });

    }

    private void showBottomPopwin() {
        BottomSelectPhotosPopwin popwin = new BottomSelectPhotosPopwin(mContext);
        popwin.setOnSureClickListener(new BottomSelectPhotosPopwin.OnSureClickListener() {
            @Override
            public void openAlbum() {
                selectAlbum();
            }

            @Override
            public void openCamera() {
                selectCamera();
            }
        });
    }

    //选择相册
    private void selectAlbum() {
        Widget widget = Widget.newDarkBuilder(mContext).title("选择图片").statusBarColor(getResources().getColor(R.color.colorAccent)).toolBarColor(getResources().getColor(R.color.colorAccent)).build();
        Album.image(mContext).singleChoice().widget(widget).camera(false).columnCount(3).onResult(new Action<ArrayList<AlbumFile>>() {
            @Override
            public void onAction(@NonNull ArrayList<AlbumFile> result) {
                // 拿到用户选择的图片路径List：
                headImgPath = result.get(0).getPath();
//                updateHeadimg(new File(result.get(0).getPath()));
                Glide.with(mContext).load(headImgPath).into(stvAvatar.getRightIconIV());
            }
        }).start();

    }

    private void selectCamera() {
        Album.camera(mContext).image().onResult(new Action<String>() {
            @Override
            public void onAction(@NonNull String result) {
                headImgPath = result;
//                updateHeadimg(new File(result.get(0).getPath()));
                Glide.with(mContext).load(headImgPath).into(stvAvatar.getRightIconIV());
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
